package com.iflytek.shiro;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class shiroDay1 {
    public static void main(String[] args) {
        IniSecurityManagerFactory factory=new IniSecurityManagerFactory("classpath:shiro.ini");
        SecurityManager securityManager= (SecurityManager) factory.getInstance();
        SecurityUtils.setSecurityManager((org.apache.shiro.mgt.SecurityManager) securityManager);
        Subject subject=SecurityUtils.getSubject();
        UsernamePasswordToken token=new UsernamePasswordToken("admin","root");
        try{
            subject.login(token);
            System.out.println("身份验证成功");
        }catch (AuthenticationException e){
        e.printStackTrace();
        System.out.println("身份验证失败");}
        subject.logout();
    }
}
